#include "gaussian.h"
#include "cstdlib.h"
#include "cmath.h"

//using namespace std;

double getgaussian()
{
    double result;
    double x, y;
    double tmp;
    
    do
    {
        x=2.0*rand()/RAND_MAX-1;
        y=2.0*rand()/RAND_MAX-1;
        tmp=x*x+y*y;
    }while(tmp>=1.0);
    
    result=x*sqrt(-2*log(tmp)/tmp);
    
    return tmp;
}